<!--
 * @Author: bln
 * @Date: 2024-08-19 00:00:00
 * @FilePath: dev\pages\law\components\attachmentUpload.vue
 * @Description: 附件展示页面
-->

<template>
  <view class="page" v-if="fileList.length>0">
    <view class="main-content" v-for="(item,index) in fileList" :key="index">
      <u-row>
        <u-col span="1"><u-icon name="attach" width="42" height="48" color="#2979ff" size="34"></u-icon></u-col>
        <u-col span="7.5" style="word-break: break-word;">{{ item.name }}</u-col>
        <u-col span="2.5" style="text-align: right;color: #3381ff;"><span @click="upload(item)">点击下载</span></u-col>
        <u-col span="1"><u-icon name="download" color="#2979ff" size="30" @click="upload(item)"></u-icon></u-col>
      </u-row>
    </view>
  </view>
</template>

<script>
import queryService from '@/service/check/query.service'
import certificateService from '@/service/certificate/certificate.service.js'

const IMG_LIST = ['image/gif', 'image/jpg', 'image/jpeg', 'image/bmp', 'image/png']

export default{
  props:['noticeUuid'],
  data(){
    return {
      fileList:[],
      picTypeList: IMG_LIST,
    }
  },
  created(){
    this.init()
  },
  methods:{
    init(){
      certificateService.goFiles(this.noticeUuid, '').then(res => {
        this.picList = res.data
        this.fileList = this.picList.map((f) => {
          f.uid = f.fileId = f.gfiId
          f.name = f.gfiAlis + (this.showUploader ? `（${f.gfiUser}）` : '')
          f.status = 'done'
          f.size = f.gfiSize
          f.url = queryService.previewImg(f.gfiId)
          if (this.picTypeList.join(',').indexOf(f.gfiSuffix) != -1) {
            f.type = 'image/' + f.gfiSuffix
          }
          return f
        })
      })
    },
    upload(item){
      this.$modal.downloadFile(item.url, item.name)
    }
  }
}
</script>

<style scoped lang="scss">
.page {
  width: 100%;
  padding: 8rpx 8rpx 0rpx 8rpx;
}
.main-content {
  padding: 20rpx 0 20rpx 0;
  border-bottom: 2rpx solid $u-border-color;
}
</style>